<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/22
 * Time: 17:21
 */

namespace app\api\controller\v1;
use app\api\model\Category as CategoryModel;
use app\lib\exception\CategoryException;
use think\Controller;
use think\Db;

class Category extends Controller
{

    /**
     * @api {get} /category/all 获取所有分类
     * @apiName getAllCategory
     * @apiGroup Category
     *
     * @apiSuccess {int} id 分类id
     * @apiSuccess {String} name 标题
     * @apiSuccess {varchar} pic 图片
     */
    public function getAllCategory(){

        $categories = Db::name('product_cate')->where('status','1')->field('id,name,pic')->select();
//        $categories = CategoryModel::Where('status','1')->select();
        if($categories->isEmpty()){
            throw new CategoryException();
        }
        return $categories;
    }
}